package org.xteam.camllight;

import java.io.File;

public class Sys {
	
	private static String[] pathes = System.getenv("PATH").split(":");

	public static String searchpath(String name) {
		for (int i = 0; i < name.length(); ++i) {
		    if (name.charAt(i) == '/')
		    	return name;
		  }
		  if (pathes.length == 0)
			  return null;
		  StringBuilder fullname = new StringBuilder();
		  for(String path : pathes) {
			  fullname.append(path);
			  if (fullname.length() == 0) {
				  fullname.append('/');
			  }
			  fullname.append(name);
			  File st = new File(fullname.toString());
			  if (st.exists() && st.isFile()) {
				  return fullname.toString();
			  }
		  }
		  return null;
	}
}
